{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": [
     "notebook-header"
    ]
   },
   "source": [
    "[![GitHub issues by-label](https://img.shields.io/github/issues-raw/pfebrer/sisl/FatbandsPlot?style=for-the-badge)](https://github.com/pfebrer/sisl/labels/FatbandsPlot)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "    \n",
    "    \n",
    "FatbandsPlot\n",
    "========="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sisl"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For this notebook we will create a toy \"Boron nitride\" tight binding:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# First, we create the geometry\n",
    "BN = sisl.geom.graphene(atoms=[\"B\", \"N\"])\n",
    "\n",
    "# Create a hamiltonian with different on-site terms\n",
    "H = sisl.Hamiltonian(BN)\n",
    "\n",
    "H[0, 0] = 2\n",
    "H[1, 1] = -2\n",
    "\n",
    "H[0, 1] = -2.7\n",
    "H[1, 0] = -2.7\n",
    "\n",
    "H[0, 1, (-1, 0)] = -2.7\n",
    "H[0, 1, (0, -1)] = -2.7\n",
    "H[1, 0, (1, 0)] = -2.7\n",
    "H[1, 0, (0, 1)] = -2.7"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that we could have obtained this hamiltonian from any other source. Then we generate a path for the band structure:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "band = sisl.BandStructure(\n",
    "    H,\n",
    "    [[0.0, 0.0], [2.0 / 3, 1.0 / 3], [1.0 / 2, 1.0 / 2], [1.0, 1.0]],\n",
    "    301,\n",
    "    [r\"Gamma\", \"K\", \"M\", r\"Gamma\"],\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And finally we just ask for the fatbands plot:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fatbands = band.plot.fatbands()\n",
    "fatbands"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We only see the bands here, but this is a fatbands plot, and it is ready to accept your requests on what to draw!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Requesting specific weights\n",
    "\n",
    "The fatbands that the plot draws are controlled by the `groups` setting. This setting works exactly like the `groups` setting in `PdosPlot`, which is documented [here](./PdosPlot.ipynb). Therefore we won't give an extended description of it, but just quickly show that you can autogenerate the groups:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fatbands.split_orbs(on=\"species\", name=\"$species\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Or write them yourself if you want the maximum flexibility:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fatbands.update_inputs(\n",
    "    groups=[\n",
    "        {\"species\": \"N\", \"color\": \"blue\", \"name\": \"Nitrogen\"},\n",
    "        {\"species\": \"B\", \"color\": \"red\", \"name\": \"Boron\"},\n",
    "    ]\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Scaling fatbands\n",
    "\n",
    "The visual appeal of fatbands depends a lot on the size of your plot, therefore there's one global `scale` setting that scales all fatbands at the same time:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "nbsphinx-thumbnail"
    ]
   },
   "outputs": [],
   "source": [
    "fatbands.update_inputs(fatbands_scale=2).show(\"png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Use BandsPlot settings\n",
    "\n",
    "All settings of `BandsPlot` work as well for `FatbandsPlot`."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
